package com.heny.nc.service;

import com.heny.demo.common.CommonErrorCode;
import com.heny.demo.common.CommonException;
import com.heny.nc.model.NCModel;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * @author litao.cc
 * @version SaveDataProcessorStrategy.java v0.1 t2025/4/26 18:40
 * @date 2025/4/26 18:40
 * @description 数据存储
 */
public abstract class AbstractSaveDataProcessor {

    public List<String> apply(Map<Integer, List<NCModel>> data,String path,String baseFileName){
        File folder = new File(path);
        // 判断文件夹是否存在,不存在创建
        if (!folder.exists()) {
            boolean success = folder.mkdirs();
            if (!success) {
                throw new CommonException(CommonErrorCode.SYSTEM_ERROR, "文件夹创建失败！");
            }
        }

        return save(data,path,baseFileName);
    }

    abstract List<String> save(Map<Integer, List<NCModel>> data,String path,String baseFileName);



    // 工具
    protected String buildSavePath(String path, String baseFileName, String d,String type) {
        return path + "\\" + baseFileName + d + "."+type;
    }
}
